//# sourceURL=http://uMapApp/Module/Bridge/BridgeDetectionNode
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../../UI/Layer"
    , "../../Earth/ViewPort"
], function (
    mhjs,
    uMap,
    uEarth,
    Layer,
    ViewPort
) {

    function BridgeDetectionNode(option) {
        var _this = this;
        option && _this.OptionToProperties(option);

        _this.status = _this.dic.status[_this.status || "0"];
        _this.type = _this.dic.type[_this.typeCode || "0"];

        if (_this.position) {

            _this.title = _this["名称"] + " / " + _this["节点类型"] + " / " + _this["节点ID"];
            _this.searchKey = _this["名称"] + " " + _this["节点类型"] + " " + _this["节点ID"];
            _this.sortKey = _this["节点ID"];

            _this.layer = new Layer({
                "app"     : _this.app,
                "viewport": new ViewPort({
                    "center": _this.position,
                    "hpr"   : {
                        "heading": 23,
                        "pitch"  : -20,
                        "range"  : 100
                    }
                })
            });

            // if (_this.bridge) {
            //     _this.layer.dataSource = _this.bridge.layer.dataSource;
            // }

            _this.marker = new uMap.Entity({
                objectOption: {
                    position: _this.position,
                    point   : new uMap.PointGraphic({
                        objectOption: {
                            color                     : [_this.status.color],
                            pixelSize                 : 10
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    }),
                    label   : new uMap.LabelGraphic({
                        objectOption: {
                            text                      : _this["名称"],
                            verticalOrigin            : "TOP"
                            , pixelOffset             : [0, 10]
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    })
                }
            });
            _this.layer.dataSources.entities.add(_this.marker.object);

            _this.marker.on("click", function () {
                _this.trigger("click");
            });
        }


    }

    var _class = BridgeDetectionNode;

    mhjs.OptionToPropertiesInterface(_class);
    mhjs.EventInterface(_class);

    Object.defineProperties(_class.prototype, {
        "open"    : {
            value: function () {

                var _this = this;

                if (!_this.isOpened) {

                    _this.layer && _this.layer.open();
                    _this.isOpened = true;
                    _this.trigger("open");
                }
            }
        },
        "close"   : {
            value: function () {

                var _this = this;

                if (_this.isOpened) {

                    _this.layer && _this.layer.close();
                    _this.isOpened = false;
                    _this.trigger("close");
                }
            }
        },
        "toggle"  : {
            value: function () {
                if (this.isOpened) {
                    this.close();
                } else {
                    this.open();
                }
            }
        },
        "active"  : {
            value: function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {

                        if (_this.layer) {
                            // _this.layer.active();
                        }

                        _this.marker.label.fillColor = new uMap.Color(["#ff0"]);
                        _this.marker.label.scale = 1.2;
                        _this.marker.point.pixelSize = 15;

                        _this.trigger("active");

                    } else {

                        if (_this.layer) {
                            // _this.layer.dataSourceView.close();
                        }

                        _this.marker.label.fillColor = new uMap.Color(["#FFF"]);
                        _this.marker.label.scale = 1;
                        _this.marker.point.pixelSize = 10;

                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }


            }
        },
        "loadData": {
            value: function (callback) {
                var _this = this;

                if (!_this.isDataLoaded && _this.dataRequest) {

                    _this.app.queryManager.modalityLoading.open();
                    _this.app.queryManager.modalityLoading.info = "正在加载节点数据";

                    _this.dataRequest.send({
                        "nodeId"     : _this["节点ID"],
                        "orderByName": "createTime",
                        "orderByType": "DESC",
                        "pageSize"   : 500,
                        "pageNo"     : 1
                    }, function (json) {
                        _this.data = json.data.list;
                        _this.isDataLoaded = true;

                        _this.app.queryManager.modalityLoading.close();

                        callback && callback();
                    });
                } else {
                    callback && callback();
                }


            }
        }
    });

    return _class;

});